home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 361_01 / keys.c < prev    next >
C/C++ Source or Header  |  1991-09-18  |  4KB  |  97 lines

  1.  
  2.  
  3. /* Keys --> Report ASCII Value, ScanCode & KeyMask on Key Hit.
  4.  *
  5.  * J.Ekwall
  6.  *
  7.  * Copyrighted to the Public Domain.  Unlimited Distribution Authorized.
  8.  *
  9.  * User Assumes All Risks/Liabilities.
  10.  *
  11.  * Last Update:  6 June 91/EK
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <io.h>
  16. #include <bios.h>
  17. #include <stdek.h>
  18.  
  19. /* Set Up Keyboard ScanCode/Character Union */
  20. union Keypunch {
  21.    int C;
  22.    BYTE Chr[2];
  23. } KeyStroke;
  24.  
  25. /* Set Up Control Chr Lookup Table */
  26. char *CtrlCode[] = {
  27.    "NULL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "NL",
  28.    "VT", "FF", "CR", "SO", "SI", "DLE", "XON", "DC2", "XOFF", "DC4", "NAK",
  29.    "SYN", "ETB", "CAN", "EOM", "SUB", "ESC", "FS", "GS", "RS", "US", NULL };
  30.  
  31. /* Set Up ScanCode Lookup Table */
  32. char *ScanCode[] = {
  33.    "ALT_BS ",   "SHIFT_HT",     "ALT_Q",        "ALT_W",        "ALT_E",
  34.    "ALT_R",     "ALT_T",        "ALT_Y",                "ALT_U",        "ALT_I",
  35.    "ALT_O",     "ALT_P",        "ALT_LBRACE ",  "ALT_RBRACE ",  "ALT_RTN        ",
  36.    "EK157",     "ALT_A",        "ALT_S",                "ALT_D",        "ALT_F",
  37.    "ALT_G",     "ALT_H",        "ALT_J",                "ALT_K",        "ALT_L",
  38.    "ALT_SEMI ", "ALT_QUOTE ",   "ALT_TILDE ",   "EK170",        "ALT_BKSL ",
  39.    "ALT_Z",     "ALT_X",        "ALT_C",                "ALT_V",        "ALT_B",
  40.    "ALT_N",     "ALT_M",        "ALT_COMMA ",   "ALT_DOT ",     "ALT_QUERY ",
  41.    "EK182",     "ALT_STAR ",    "EK184",        "EK185",        "EK186",
  42.    "F1",        "F2",                   "F3",                   "F4",                   "F5",
  43.    "F6",        "F7",                   "F8",                   "F9",                   "F10",
  44.    "EK197",     "EK198",        "HOME",         "UP",           "PGUP",
  45.    "ALT_MINUS ","BWD",          "EK204 ",       "FWD",          "ALT_PLUS ",
  46.    "END",       "DN",           "PGDN", "INS",          "DEL_KEY",
  47.    "SHIFT_F1",  "SHIFT_F2",     "SHIFT_F3",     "SHIFT_F4",     "SHIFT_F5",
  48.    "SHIFT_F6",  "SHIFT_F7",     "SHIFT_F8",     "SHIFT_F9",     "SHIFT_F10",
  49.    "CTL_F1",    "CTL_F2",               "CTL_F3",       "CTL_F4",       "CTL_F5",
  50.    "CTL_F6",    "CTL_F7",               "CTL_F8",       "CTL_F9",       "CTL_F10",
  51.    "ALT_F1",    "ALT_F2",               "ALT_F3",        "ALT_F4",      "ALT_F5",
  52.    "ALT_F6",    "ALT_F7",               "ALT_F8",       "ALT_F9",       "ALT_F10",
  53.    "EK242",     "CTL_BWD",              "CTL_FWD",      "CTL_END",              "CTL_PGDN",
  54.    "CTL_HOME",  "ALT_1",        "ALT_2",        "ALT_3",        "ALT_4",
  55.    "ALT_5",     "ALT_6",        "ALT_7",                "ALT_8",        "ALT_9",
  56.    "ALT_0",     "ALT_DASH",     "ALT_EQUALS",           "CTL_PGUP",     "F11 ",
  57.    "F12 ",      "SHIFT_F11 ",   "SHIFT_F12 ",   "CTL_F11 ",     "CTL_F12        ",
  58.    "ALT_F11 ",  "ALT_F12 ",     "CTL_UP ",              "CTL_DASH ",    "CTL_5 ",
  59.    "CTL_PLUS ", "CTL_DN ",      "CTL_INS ",             "CTL_DEL_KEY ", "CTL_HT ",
  60.    "CTL_SL ",   "CTL_STAR ",    "ALT_HOME ",    "ALT_UP ",      "ALT_PGUP ",
  61.    "EK282 ",    "ALT_BWD ",     "EK284 ",       "ALT_FWD ",     "EK286 ",
  62.    "ALT_END ",  "ALT_DN ",      "ALT_PGDN ",    "ALT_INS ",     "ALT_DEL_KEY ",
  63.    "ALT_SL ",   "ALT_HT ",      "ALT_ENTER ",   NULL };
  64.  
  65. main (int argc, char *argv[])
  66. {
  67.     int c, KeyCode, Silent = FALSE;
  68.     char *tp1;
  69.  
  70.     if (argc IS 2 && *argv[1] IS SLASH && toupper(argv[1][1]) IS 'S')
  71.        Silent = TRUE;
  72.     else {
  73.        printf("\nKey Stroke Test.  Hit [Esc] to Exit.  Hit Any Key.\n\n");
  74.        printf("\tAscii\tScanCode\tKeyMask\t\tKeys.h\t\tSymbol\n");
  75.     }
  76.  
  77.     do {
  78.        KeyStroke.C = bioskey(0);
  79.        if ((c = KeyStroke.Chr[0]) != 0) KeyCode = c;
  80.        else KeyCode = KeyStroke.Chr[1] | 128;
  81.        if (Silent) exit(KeyCode);
  82.        printf("\t%u\t%u\t\t%d\t\t%d\t",
  83.        KeyStroke.Chr[0], KeyStroke.Chr[1], bioskey(2), KeyCode);
  84.        if (c) {
  85.           if(c  < SPACE)
  86.              printf("\t%s\n", CtrlCode[c]);
  87.           else
  88.              printf("\t\"%c\"\n", c);
  89.        } else if ((c = KeyStroke.Chr[1]) >= 14 && c < 167) {
  90.           tp1 = ScanCode[c-14];
  91.           if (tp1[strlen(tp1)-1] IS SPACE) printf("NewKey");
  92.           printf("\t%s\n", ScanCode[c-14]);
  93.        } else if (c IS 1) printf("NewKey\tALT_ESC\n");
  94.     } while (KeyStroke.Chr[0] != ESC);
  95. }
  96.  
  97.